﻿Imports Publics

Public Class FrmChonThanhVien

    Private _objThanhVien As DM_ThanhVien
    Public Property objThanhVien() As DM_ThanhVien
        Get
            Return _objThanhVien
        End Get
        Set(ByVal value As DM_ThanhVien)
            _objThanhVien = value
        End Set
    End Property

    Private Sub FrmChonThanhVien_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Windows.Forms.Keys.Enter Then
            btnChon_ItemClick(Nothing, Nothing)
        End If
        If e.KeyCode = Windows.Forms.Keys.Escape Then
            btnThoat_ItemClick(Nothing, Nothing)
        End If
    End Sub

    Private Sub FrmChonThanhVien_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FillDataToGrid()
    End Sub
    Private Sub FillDataToGrid()
        grdThanhVien.DataSource = (From ds In dbTV.DM_ThanhViens Where ds.InUsed Order By ds.MaThanhVien Select New With { _
                                      .ID = ds.ID, .MaThanhVien = ds.MaThanhVien, .TenThanhVien = ds.HoTenThanhVien, .DiaChi = ds.DiaChi, _
                                      .DienThoai = ds.SoDT, .CapBac = ds.CapBac.GetValueOrDefault, .Diem = ds.Diem, _
                                      .TienThanhToan = ds.TienThanhToan.GetValueOrDefault, .NgaySinh = ds.NgaySinh}).ToList
        grdThanhVien.RefreshDataSource()
    End Sub

    Private Sub btnChon_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnChon.ItemClick
        If grvThanhVien.FocusedRowHandle < 0 Then
            Return
        End If
        Dim strID = grvThanhVien.GetRowCellValue(grvThanhVien.FocusedRowHandle, grdColIDThanhVien).ToString
        Dim obj = (From ds In dbTV.DM_ThanhViens Where ds.InUsed AndAlso ds.ID = strID Select ds).FirstOrDefault
        If obj IsNot Nothing Then
            objThanhVien = obj
            Me.Close()
        End If

    End Sub

    
    Private Sub btnThoat_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnThoat.ItemClick
        objThanhVien = Nothing
        Me.Close()
    End Sub
End Class